<?php
  /**
  * Add event to log
  */
  if ($_POST['submitted']) 
  {
      include('data/lib_f_validate.inc.php');
      extract($_POST);
      if($logtext && !$logtext = validateText($logtext)){$err .= 'Text is invalid!<br>';$logtext = $_POST['logtext'];}
      if (!$err)
      {
          logevent($logtext);
      } else $content .= $err.'<br><br>';
  }      
  /**
   * Display add to log form
   */
  $content = "<h3>Add something to the log?</h3>";
  $content .= '<form name="log" method="post" target="_self" title="Add to log?">
            <textarea name="logtext" id="logtext" rows="2" cols="50" wrap="virtual">'.$text.'</textarea>
            <input type="hidden" name="submitted" value="1">
            <input type="hidden" name="MID" value="'.$_SESSION['MID'].'">
            <input type="submit" name="go" id="go" value="Go!">
         </form><hr />';
  
  $logentries = 40;
  /**
  * Display log list
  */
  if ($res = mq("SELECT LID, Context, Detail, Date, Name FROM log l
                 INNER JOIN members m on m.MID=l.MID
                 ORDER BY Date DESC LIMIT ".$logentries)) 
  {
      $content .= 'Here is the log of all administrative activities:<br>
                      <table cellpadding="3">';
      while($data = mysql_fetch_array($res))
      {
          $content .= '<tr>
                           <td><b>'.$data['Name'].'</b> in &quot;'.$data['Context'].'&quot;</td>
                           <td style="text-align:right">'.$data['Date'].'</td>
                         </tr><tr>  
                           <td colspan="2">'.$data['Detail'].'</td>
                         </tr>';
      }
      $content .= '</table>';
                        
  } else $content = 'No log entries yet.<br>';
?>